javac target option for previous versions

chris (2004-06-07 16:33:44)
3553 views
0 replies
I had a requirement to test the Java runtime environment on a user's computer to ensure that they have support for Java 1.4 or above. I had a small applet which did the job, but had to be sure that it would run on the MS JVM (and others) for those users who haven't yet installed a 'proper' JVM. So to setup a test case I used the following applet code:

import java.applet.*;

public class Moo extends java.applet.Applet {
public void start() {
System.out.println(" this is a test");
}
}


the applet is compiled into jvm_test.html and embeded with the following line:
<APPLET code="Moo.class" width=10 height=10></APPLET>

however the MS JVM errors when jvm_test.html is loaded with the following
stacktrace:
Error loading class: Moo 
java.lang.NoClassDefFoundError 
java.lang.ClassNotFoundException: Moo 
at com/ms/vm/loader/URLClassLoader.loadClass 
at com/ms/vm/loader/URLClassLoader.loadClass 
at com/ms/applet/AppletPanel.securedClassLoad 
at com/ms/applet/AppletPanel.processSentEvent 
at com/ms/applet/AppletPanel.processSentEvent 
at com/ms/applet/AppletPanel.run 
at java/lang/Thread.run 

even though Moo.class is in the same directory as jvm_test.html.

The simple solution to this problem was to recompile adding the option '-target 1.1' when using javac, so the compilation looked like:

$ javac -target 1.1 Moo.java


problem solved
christo
comment